package com.vb.ecm.server.jobs;

import com.documentum.com.DfClientX;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.IDfLoginInfo;

public class DfcSessionManager {

	private IDfSessionManager m_sessionMgr;
	private String m_repository;
	private String m_userName;
	private String m_password;
	
	public DfcSessionManager(String rep, String user, String pword) {
		try {
		
				m_repository = rep;
				m_userName = user;
				m_password = pword;
			
				m_sessionMgr = createSessionManager();
			}
				catch (Exception e) {
				System.out.println("An exception has been thrown: " + e);
				}
	}
	
	public DfcSessionManager() {
		try {
		
				m_repository = "documentum_test";
				m_userName = "hieunm";
				m_password = "hieunm";
			
				m_sessionMgr = createSessionManager();
			}
				catch (Exception e) {
				System.out.println("An exception has been thrown: " + e);
				}
	}
	
	private IDfSessionManager createSessionManager() throws Exception {
		
		DfClientX clientx = new DfClientX();
		
		IDfClient client = clientx.getLocalClient();
	
		IDfSessionManager sMgr = client.newSessionManager();
		
		IDfLoginInfo loginInfo = clientx.getLoginInfo();
		loginInfo.setUser(m_userName);
		loginInfo.setPassword(m_password);
		
		sMgr.setIdentity(m_repository, loginInfo);
		
		return sMgr;
		}
		public IDfSession getSession() throws DfException {
		return m_sessionMgr.getSession(m_repository);
		}
			public void releaseSession(IDfSession session) {
			m_sessionMgr.release(session);
		}
}
